'use strict';

angular.module('app')
    .config(['$stateProvider', '$urlRouterProvider',
        function ($stateProvider, $urlRouterProvider) {
            // 日志部分
            $stateProvider.state('app.system', {
                url: '/system',
                template: '<div ui-view></div>',
                data: {
                    authorities: ['IS_AUTHENTICATED_FULLY']
                },
                resolve: {
                    deps: ['$ocLazyLoad',
                        function ($ocLazyLoad) {
                    		return $ocLazyLoad.load(['ui.select']);   
                        }]
                }
            }).state('app.system.log', {
                url: '/log',
                template: '<div ui-view></div>',
                data: {
                    authorities: ['IS_AUTHENTICATED_FULLY']
                }
            })
                .state('app.system.log.list', {
                    url: '/list',
                    templateUrl: 'tpl-system/log/list.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                        		return $ocLazyLoad.load(['tpl-system/log/list.js']);   
                            }]
                    }
                })
                // 数据字典部分
                .state('app.system.dictionary', {
                    url: '/dictionary',
                    template: '<div ui-view></div>',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    }
                })
                .state('app.system.dictionary.list', {
                    url: '/list',
                    templateUrl: 'tpl-system/dictionary/list.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/dictionary/list.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.dictionary.edit', {
                    url: '/edit/:id/:type',
                    templateUrl: 'tpl-system/dictionary/edit.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/dictionary/edit.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.dictionary.view', {
                    url: '/view/:id/:type',
                    templateUrl: 'tpl-system/dictionary/view.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/dictionary/view.js'
                                ]);
                            }]
                    }
                })
                // 系统配置部分
                .state('app.system.config', {
                    url: '/config',
                    template: '<div ui-view></div>',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    }
                })
                .state('app.system.config.list', {
                    url: '/list',
                    templateUrl: 'tpl-system/config/list.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/config/list.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.config.edit', {
                    url: '/edit/:id/:type',
                    templateUrl: 'tpl-system/config/edit.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/config/edit.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.config.view', {
                    url: '/view/:id/:type',
                    templateUrl: 'tpl-system/config/view.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/config/edit.js'
                                ]);
                            }]
                    }
                })
                // 权限部分
                .state('app.system.authority', {
                    url: '/authority',
                    template: '<div ui-view></div>',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    }
                })
                .state('app.system.authority.tree', {
                    url: '/tree',
                    templateUrl: 'tpl-system/authority/tree.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/authority/tree.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.authority.tree.view', {
                    url: '/view',
                    params : {
                    	entity : 'entity'
                    },
                    templateUrl: 'tpl-system/authority/view.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/authority/view.js'
                                ]);
                            }]
                    }
                })
                // 角色部分
                .state('app.system.role', {
                    url: '/role',
                    template: '<div ui-view></div>',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    }
                })
                .state('app.system.role.list', {
                    url: '/list',
                    templateUrl: 'tpl-system/role/list.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/role/list.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.role.list.viewAuth', {
                    url: '/viewAuth/:id',
                    templateUrl: 'tpl-system/role/viewAuth.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/role/viewAuth.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.role.list.editAuth', {
                    url: '/editAuth/:id',
                    templateUrl: 'tpl-system/role/editAuth.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/role/editAuth.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.role.edit', {
                    url: '/edit/:id/:type',
                    templateUrl: 'tpl-system/role/edit.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                        		return $ocLazyLoad.load(['tpl-system/role/edit.js']);   
                            }]
                    }
                })
                .state('app.system.role.view', {
                    url: '/view/:id/:type',
                    templateUrl: 'tpl-system/role/view.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/role/edit.js'
                                ]);
                            }]
                    }
                })

                // 组部分
                .state('app.system.group', {
                    url: '/group',
                    template: '<div ui-view></div>',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    }
                })
                .state('app.system.group.list', {
                    url: '/list',
                    templateUrl: 'tpl-system/group/list.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                        		return $ocLazyLoad.load(['treetable']).then(
                                    function () {
                                        return $ocLazyLoad.load(['tpl-system/group/list.js']);
                                    }
                                );
                            }]
                    }
                })
                 .state('app.system.group.edit', {
                    url: '/edit/:id/:type/:parentId',
                    templateUrl: 'tpl-system/group/edit.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                        		return $ocLazyLoad.load(['tpl-system/group/edit.js']);  
                            }]
                    }
                })
                .state('app.system.group.view', {
                    url: '/view/:id',
                    templateUrl: 'tpl-system/group/view.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                        		return $ocLazyLoad.load(['tpl-system/group/view.js']);
                            }]
                    }
                })

                // 区域部分
                .state('app.system.region', {
                    url: '/region',
                    template: '<div ui-view></div>',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    }
                })
                .state('app.system.region.list', {
                    url: '/list',
                    templateUrl: 'tpl-system/region/list.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                        		return $ocLazyLoad.load(['treetable']).then(
                                    function () {
                                        return $ocLazyLoad.load(['tpl-system/region/list.js']);
                                    }
                                );
                            }]
                    }
                })
                .state('app.system.region.edit', {
                    url: '/edit/:id/:type/:parentId',
                    templateUrl: 'tpl-system/region/edit.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                        	return $ocLazyLoad.load(['tpl-system/region/edit.js']);
                            }]

                    }
                })
                .state('app.system.region.view', {
                	url: '/view/:id',
                    templateUrl: 'tpl-system/region/view.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                			return $ocLazyLoad.load(['tpl-system/region/view.js']);
                		}]
                	
                	}
                })

                // 用户部分
                .state('app.self', {
                    url: '/self/',
                    templateUrl: 'tpl-system/user/updateSelf.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['ngImgCrop']).then(
                                    function () {
                                        return $ocLazyLoad.load(['tpl-system/user/updateSelf.js', 'js/controllers/imgcrop.js']);
                                    }
                                );
                            }]
                    }
                })
                // 用户部分
                .state('app.system.user', {
                    url: '/user',
                    template: '<div ui-view></div>',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    }
                })
                .state('app.system.user.list', {
                    url: '/list',
                    templateUrl: 'tpl-system/user/list.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    params: {
                        isAdmin: 'isUser'
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'tpl-system/user/list.js'
                                ]);
                            }]
                    }
                })
                .state('app.system.user.edit', {
                    url: '/edit/:id/:type',
                    templateUrl: 'tpl-system/user/edit.html',
                    data: {
                        authorities: ['IS_AUTHENTICATED_FULLY']
                    },
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                        		return $ocLazyLoad.load(['tpl-system/user/edit.js']);   
                            }]
                    }
                })
                .state('app.system.user.view', {
                	url: '/view/:id',
                	templateUrl: 'tpl-system/user/view.html',
                	data: {
                		authorities: ['IS_AUTHENTICATED_FULLY']
                	},
                	resolve: {
                		deps: ['$ocLazyLoad',
                		       function ($ocLazyLoad) {
                			return $ocLazyLoad.load(['tpl-system/user/view.js']);
                		}]
                	}
                })
        }])